public class project {
    public String truncateSentence(String s, int k) {
        String[] str=s.split(" ");
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<k;i++){
            if(i==k-1){
                sb.append(str[i]);
            }else{
                sb.append(str[i]+" ");
            }
        }
        return sb.toString();
    }
}
